package cn.doitedu.day03

/**
 * 对数组或集合进行排序，还可以使用sorted和sortWith
 */
object SortedAndSortWith {

  def main(args: Array[String]): Unit = {

    val arr: Array[Int] = Array(1, 7, 3, 5, 9, 2, 4, 7, 8, 6, 11, 12, 20)

    //按照数组或集合中原来数据类型，升序排序
    val sorted = arr.sorted

    //如果想要降序排序
    val res = arr.sorted(Ordering[Int].reverse)


    //sortWith
    val f = (x: Int, y: Int) => x > y
    val res2: Array[Int] = arr.sortWith(f)


    val res3 = arr.sortWith((a, b) => a > b)
    val res4 = arr.sortWith(_ > _)


    val res5 = arr.sortWith(_.toString > _.toString)

  }

}
